'use strict';

// let fileName = 'test3.vue'
// let filePath = 'D:\\projects\\learn\\code-maker-browser\\server\\files\\test3.vue'

// eslint-disable-next-line no-undef
window.vvg.blocksCommon = function () {
  return function(addNodes, {parentNode} = {}) {
    let _ret = {}
    let filePath = window.vvg.curFile.path
    window.vvg.blocks.save = function () {

      let tpl =
  window.ART.render(`
<template>
${vvg.page.html}
</template>

<script>${vvg.page.js}</script>

<style>${vvg.page.css}</style>
`.trim(), {
    blocks: window.vvg.page.ext
  })


      window.axios.put('/api/putfile', {
        tpl,
        file: filePath
      })
    }

    function reload() {

      return new Promise(function(resolve) {
        window.axios.get('/api/getfile', {
          params: {
            file: filePath
          }
        }).then(res => {
          _ret = globalThis.parseVue(res.data.tpl)
          resolve(_ret)
        })
      });
    }

    return {
      reload
    }
  };
}
